package com.weasel.im.common.codec;

import com.weasel.helper.JsonHelper;
import com.weasel.im.common.domain.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

/**
 * Created by Dylan on 2015/12/4.
 */
public class WebsocketMessageDecoder extends MessageToMessageDecoder<TextWebSocketFrame> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame textWebSocketFrame, List<Object> list) throws Exception {

        String jsonMessage = textWebSocketFrame.text();
        Message message = JsonHelper.fromJsonString(jsonMessage,Message.class);
        list.add(message);
    }
}
